<template>
  <div style="text-align: center;margin: 0 20px">
    <div style="margin-top: 150px">
      <div style="font-size: 25px;font-weight: bold">登录</div>
      <div style="font-size: 14px;color:grey">在进入系统之前，请先输入用户名和密码进行登录</div>

    </div>
    <div style="margin-top: 50px">
      <el-form :model="form" :rules="rules" ref="formRef">
        <el-form-item prop="username" >
          <el-input   v-model="form.username" type="text" placeholder="用户名/邮箱" maxlength="10">
          <template #prefix>
            <el-icon color="black">
              <User />
            </el-icon>
          </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input  v-model="form.password" type="password" placeholder="密码" maxlength="16">
          <template #prefix>
            <el-icon color="black">
              <Lock />
            </el-icon>
          </template>
          </el-input>
        </el-form-item>
        <el-row :gutter="10" style="width: 100%">
          <el-col :span="12" style="text-align: left">
            <el-checkbox  v-model="form.remember" style="float:left ">记住密码</el-checkbox>
          </el-col>
          <el-col :span="12" style="text-align: right">
            <el-link type="primary" style="float:right" @click="router.push('/forget')">忘记密码？</el-link>

          </el-col>
        </el-row>
          <el-row/>
      </el-form>

    </div>
    <div style="margin-top: 40px">
      <el-button style="width: 270px" type="primary" @click="userLogin" plain>登录</el-button>
    </div>
    <el-divider>
      <span style="font-size: 13px;color: grey">没有账号</span>
    </el-divider>
    <div style="margin-top: 30px">
      <el-button style="width: 270px" type="primary" @click="router.push('/register')" plain>注册</el-button>
    </div>

  </div>

</template>

<script setup>
import {login} from "@/net/index.js";

const rules = {
  username: [
    { required: true, message: '请输入用户名' }
  ],
  password: [
    { required: true, message: '请输入密码'}
  ]
}
const formRef = ref()
function userLogin() {
  formRef.value.validate((isValid) => {
    if(isValid) {
      login(form.username,form.password,form.remember,() =>{
        router.push("/index")
      })
    }
  });
}

import {reactive, ref} from "vue";
import {Lock, User} from "@element-plus/icons-vue";
import router from "@/router/main.js";

const form = reactive({
  username: '',
  password: '',
  remember: false
})


</script>

<style scoped>

</style>